package cn.edu.scau.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.scau.dao.BedMapper;
import cn.edu.scau.entity.Bed;
import cn.edu.scau.service.BedService;

@Service
public class BedServiceImpl implements BedService{

	@Autowired
	private BedMapper bedMapper;
	
	@Override
	public List<Bed> selectAll() {
		return bedMapper.selectAll();
	}

	@Override
	public boolean updateBedDescription(Integer bedid, String description) {
		Bed bed = bedMapper.selectByPrimaryKey(bedid);
		bed.setBeddescription(description);
		return 1==bedMapper.updateByPrimaryKeySelective(bed);
	}

	@Override
	public boolean checkOccupiedById(Integer bedid) {
		return bedMapper.selectByPrimaryKey(bedid).getBedoccupytatus();
	}

	@Override
	public boolean occupyBed(Integer bedid) {
		Bed bed = bedMapper.selectByPrimaryKey(bedid);
		//如果已被占用，则返回false
		if(bed.getBedoccupytatus())
			return false;
		bed.setBedoccupytatus(true);
		return 1==bedMapper.updateByPrimaryKeySelective(bed);
	}

	@Override
	public boolean releaseBed(Integer bedid) {
		Bed bed = bedMapper.selectByPrimaryKey(bedid);
		bed.setBedoccupytatus(false);
		return 1==bedMapper.updateByPrimaryKeySelective(bed);
	}

	@Override
	public boolean insert(Bed bed) {
		return 1==bedMapper.insertSelective(bed);
	}

	@Override
	public boolean delete(Integer bedid) {
		return 1==bedMapper.deleteByPrimaryKey(bedid);
	}

}
